#!/usr/bin/env jruby

# This file is to be used as an example of how to get a GUI interface with Ruby
# This requires you have jruby installed, paths set up properly, and run the
# script with jruby.
#
# You can find the sample code used for this file here:
# http://c2.com/cgi/wiki?JayRuby
#
# To download and learn about JRuby, go here:
# http://jruby.codehaus.org/
#
# Author: Elizabeth
#

# File hello_world_swing.rb (2007-08-13)
# A translation of Java tutorial HelloWorldSwing.java into JRuby 1.0
# http://java.sun.com/docs/books/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java


require 'java'
JFrame = javax.swing.JFrame
JLabel = javax.swing.JLabel
SwingUtilities = javax.swing.SwingUtilities


def create_and_show_gui()
  # Create and set up the window
  frame = JFrame.new("Swingin' JRuby")
  frame.set_default_close_operation(JFrame::EXIT_ON_CLOSE)


  # Add the ubiquitous Hello World label
  label = JLabel.new("Hello, JRuby 1.0. How's it swingin'?")
  frame.get_content_pane.add(label)

  # Display the window
  frame.pack
  frame.set_visible(true)
end


if $0 == __FILE__
  class HelloRunnable
    # Implement interface by including module
    include java.lang.Runnable
    def run()
      create_and_show_gui
    end
  end


  # Schedule a job for the event-dispatching thread
  # creating and showing this application's GUI
  SwingUtilities.invoke_later(HelloRunnable.new)
end




